// $codepro.audit.disable numericLiterals
/**
 * income statement panel
 */
package edu.gatech.oad.doctorsorder;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Set;

import javax.swing.JPanel;

import edu.gatech.oad.records.TreatmentRecord;
import edu.gatech.oad.user.Patient;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;

/**
 * Income statement panel displays total visit and total income in a specific
 * month
 * 
 * @author chen
 * @version 1.0
 */
public class IncomeStatPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Create the panel.
	 * 
	 * @param patientList
	 *            a list of all the patients in the system
	 * @param month
	 *            the month of the specified time whose statistics to display. 1
	 *            for January and 12 for December.
	 * @param year
	 *            the year of the specified month whose statistics to display.
	 *            Should have 4 digits
	 */
	public IncomeStatPanel(Set<Patient> patientList, int month, int year) {
		// initialize variables
		int totalVisit = 0;
		BigDecimal totalIncome = new BigDecimal(10.00);
		totalIncome = totalIncome.setScale(2);

		// calculates total visit and total income
		for (Patient tmpPat : patientList) {
			for (TreatmentRecord tmpTre : tmpPat.getPatientHistory()
					.getTreatmentRecords()) {

				GregorianCalendar currTime = new GregorianCalendar();
				currTime.setTime(tmpTre.getDate());

				if (((month - 1) == currTime.get(Calendar.MONTH))
						&& year == currTime.get(Calendar.YEAR)) {
					totalVisit += 1;
					BigDecimal tmpCost = new BigDecimal(tmpTre.getCost());
					tmpCost = tmpCost.setScale(2);
					totalIncome = totalIncome.add(tmpCost);
					totalIncome = totalIncome.setScale(2);
				}
			}
		}

		// create UI
		setLayout(new BorderLayout(0, 0));

		final JLabel title = new JLabel("Income Statement for " + month + "/" + year);
		title.setFont(new Font("Dialog", Font.BOLD, 20));
		title.setHorizontalAlignment(SwingConstants.CENTER);
		add(title, BorderLayout.NORTH);

		final JLabel content = new JLabel("<html><body><font=5>Total income: "
				+ totalIncome.toPlainString() + "$<br><br>Total Visit: "
				+ totalVisit + " person</font></body></html>");
		content.setFont(new Font("Dialog", Font.PLAIN, 16));
		content.setHorizontalAlignment(SwingConstants.CENTER);
		add(content, BorderLayout.CENTER);

	}

}
